/**
 * 
 */
package hu.myai.scenarios;

import hu.myai.api.scenarios.AbstractSceanario;
import hu.myai.model.TradeVO;
import hu.myai.model.TriggerVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 1. Stock top pivot: 3x volume and it cannot reach the upper bollinger.<br>
 * 2. Stock bottom pivot: 2x volume and shadow cross the lower bollinger.<br>
 * 3. next candle is above the lower bollinger
 * <ul>
 * <li>candle bottom is the stop loss.</li>
 * <li>entry is the pivot of the candle</li>
 * <li>take profit is the 2x(top-bottom)+bottom</li>
 * </ul>
 * 
 * @author bozbalint
 * 
 */
public class StrangeSwingScenario extends AbstractSceanario {

	/**
	 * The object used when logging debug,errors,warnings and info.
	 * */
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	/**
	 * historical value
	 * */
	private TriggerVO killedBullTr;

	/**
	 * @param name
	 */
	public StrangeSwingScenario(String name) {
		super(name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see hu.myai.api.scenarios.AbstractSceanario#strategyCalculation(hu.myai.
	 * model.TriggerVO)
	 */
	@Override
	protected void startCalculation(String name, TriggerVO value) {

		TriggerVO kbTrigger = "KilledBullTriggerName".equals(name) ? value : null;
		TriggerVO lbavTrigger = "TurningAtLowBollingerTriggerName".equals(name) ? value : null;

		if (kbTrigger != null) {
			killedBullTr = kbTrigger;
			return;
		}
		// first pattern is missing
		if (killedBullTr == null) {
			return;
		}
		// the first pattern is outdated
		if (lbavTrigger.getTick().getTimestamp() - killedBullTr.getTick().getTimestamp() > 20) {
			killedBullTr = null;
		}

		TradeVO tradeVO = new TradeVO();
		tradeVO.setSymbol(killedBullTr.getTick().getSymbol());
		tradeVO.setEP(lbavTrigger.getTick().getPivot());
		tradeVO.setSL(lbavTrigger.getTick().getLow());
		tradeVO.setTP(killedBullTr.getTick().getHigh() + killedBullTr.getTick().getHigh() * 2
				- lbavTrigger.getTick().getLow());
		tradeVO.setTradeType(0);
		tradeVO.setRisk(5);

		log.info("TradeVO: " + tradeVO);
	}
}
